package com.yanqu.road.server.manger.activity.springdraw.pb;

import com.yanqu.road.entity.activity.springdraw.data.SpringDrawUserData;
import com.yanqu.road.entity.activity.springdraw.config.SpringDrawDigRewardConfig;
import com.yanqu.road.pb.activity.SpringDrawProto;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.Map;

public class SpringDrawPb {

    /**
     * build SpringDrawDigRewardConfig
     * @param springDrawDigRewardConfig
     * @return
     */
    public static SpringDrawProto.SpringDrawDigRewardConfig.Builder buildSpringDrawDigRewardConfig(SpringDrawDigRewardConfig springDrawDigRewardConfig) {
        SpringDrawProto.SpringDrawDigRewardConfig.Builder builder = SpringDrawProto.SpringDrawDigRewardConfig.newBuilder();
        builder.setLevel(springDrawDigRewardConfig.getLevel());
        builder.setCost(springDrawDigRewardConfig.getCost());
        builder.setRewardList(springDrawDigRewardConfig.getRewardList());
        builder.setIsReview(springDrawDigRewardConfig.getIsReview());
        builder.setReward1(springDrawDigRewardConfig.getReward1());
        builder.setReward2(springDrawDigRewardConfig.getReward2());
        builder.setReward3(springDrawDigRewardConfig.getReward3());
        builder.setReward4(springDrawDigRewardConfig.getReward4());
        builder.setReward5(springDrawDigRewardConfig.getReward5());
        builder.setReward6(springDrawDigRewardConfig.getReward6());
        builder.setReward7(springDrawDigRewardConfig.getReward7());
        builder.setReward8(springDrawDigRewardConfig.getReward8());
        builder.setReward9(springDrawDigRewardConfig.getReward9());
        builder.setReward10(springDrawDigRewardConfig.getReward10());
        builder.setReward11(springDrawDigRewardConfig.getReward11());
        return builder;
    }

    /**
     * build 玩家数据
     * @param activityId
     * @param userId
     * @param userData
     * @return
     */
    public static SpringDrawProto.SpringDrawUserDataTemp.Builder buildSpringDrawUserDataTemp(int activityId, long userId, SpringDrawUserData userData) {
        SpringDrawProto.SpringDrawUserDataTemp.Builder builder = SpringDrawProto.SpringDrawUserDataTemp.newBuilder();
        builder.setActivityId(activityId);
        builder.setUserId(userId);
        if (userData != null) {
            builder.setLevel(userData.getLevel());
            builder.setDrawNum(userData.getDrawNum());
            builder.setScore(userData.getScore());
            //构建棋盘
            for (int row = 0; row < userData.getBoard().length; row++) {
                for (int col = 0; col < userData.getBoard().length; col++) {
                    if (userData.getBoard()[row][col] == 1) {
                        SpringDrawProto.SpringDrawBoardPositionTemp.Builder position = buildSpringDrawBoardPositionTemp(row, col);
                        builder.addBoard(position);
                    }
                }
            }
            //自选奖励
            for (Map.Entry<Integer, String> entry : userData.getSelfSelectRewardMap().entrySet()) {
                SpringDrawProto.SpringDrawSelfSelectRewardTemp.Builder selfSelectReward = SpringDrawProto.SpringDrawSelfSelectRewardTemp.newBuilder();
                selfSelectReward.setLevel(entry.getKey());
                selfSelectReward.setReward(entry.getValue());
                builder.addSelfSelectReward(selfSelectReward);
            }
        } else {
            builder.setLevel(1);
            builder.setDrawNum(0);
            builder.setScore(0);
        }
        return builder;
    }

    /**
     * 构建 SpringDrawBoardPositionTemp
     * @param row
     * @param col
     * @return
     */
    public static SpringDrawProto.SpringDrawBoardPositionTemp.Builder buildSpringDrawBoardPositionTemp(int row, int col) {
        SpringDrawProto.SpringDrawBoardPositionTemp.Builder position = SpringDrawProto.SpringDrawBoardPositionTemp.newBuilder();
        position.setLow(row);
        position.setCol(col);
        return position;
    }
}
